package org.nlp2rdf.navigator.util;

import java.io.File;
import java.net.URL;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

import org.dllearner.core.KnowledgeSource;
import org.dllearner.core.ReasonerComponent;
import org.dllearner.core.configurators.ComponentFactory;
import org.dllearner.kb.OWLFile;
import org.dllearner.utilities.JamonMonitorLogger;
import org.dllearner.utilities.examples.ExampleDataCollector;

import com.jamonapi.Monitor;

public class SpeedTest {

	public static void main(String[] args) {
		int totaltestsize = 1001;
		int interval = 200;
		String concept = "";
		for(int i=1;i<totaltestsize;i++){
			SortedSet<String> exampleURIs = new TreeSet<String>();
			int begin = i;
			for(;i<begin+interval;i++){
				exampleURIs.add("http://nlp2rdf.org/ontology/s"+i);
				
			}
			experimentFIC(concept, exampleURIs, interval);
			experimentPellet(concept, exampleURIs, interval);
		}
	}
	
	public static void experimentFIC(String concept, SortedSet<String> exampleURIs, int interval){
		Monitor init = JamonMonitorLogger.getTimeMonitor(SpeedTest.class ,"init" ).start();
		@SuppressWarnings("unused")
		ReasonerComponent rc = initFIC(exampleURIs);
		init.stop();
		
		System.out.println("ficinit: "+(init.getAvg()/1000)+" "+(((init.getAvg()/1000)/interval)*50000));
	}
	
	public static void experimentPellet(String concept, SortedSet<String> exampleURIs, int interval){
		Monitor init = JamonMonitorLogger.getTimeMonitor(SpeedTest.class ,"init" ).start();
		@SuppressWarnings("unused")
		ReasonerComponent rc = initPellet(exampleURIs);
		init.stop();
		
		System.out.println("pelletinit: "+(init.getAvg()/1000)+" "+(((init.getAvg()/1000)/interval)*50000));
	}
	
	public static ReasonerComponent initFIC(SortedSet<String> exampleURIs){
		ReasonerComponent rc =null;
		try{
			
			Set<KnowledgeSource> tmp = new HashSet<KnowledgeSource>();
			List<URL> urls = ExampleDataCollector.convert("files/tiger/", exampleURIs); 
			String backgroundXML = "files/tiger.noSchema.noImports.rdf";
			URL add = new File(backgroundXML).toURI().toURL();
			urls.add(add);
			for(URL u: urls){
				OWLFile ks = ComponentFactory.getOWLFile(u);
				tmp.add(ks);
			}
			rc = ComponentFactory.getFastInstanceChecker(tmp);
			for(KnowledgeSource ks:tmp){
				ks.init();
			}
			rc.init();
			
		}catch (Exception e) {
			e.printStackTrace();
		}
		return rc;
		
	}
	public static ReasonerComponent initPellet( SortedSet<String> exampleURIs){
		ReasonerComponent rc =null;
		try{
			Set<KnowledgeSource> tmp = new HashSet<KnowledgeSource>();
			List<URL> urls = ExampleDataCollector.convert("files/tiger/", exampleURIs); 
			String backgroundXML = "files/tiger.noSchema.noImports.rdf";
			URL add = new File(backgroundXML).toURI().toURL();
			urls.add(add);
			for(URL u: urls){
				OWLFile ks = ComponentFactory.getOWLFile(u);
				tmp.add(ks);
			}
			rc = ComponentFactory.getOWLAPIReasoner(tmp);
			for(KnowledgeSource ks:tmp){
				ks.init();
			}
			rc.init();
		}catch (Exception e) {
			e.printStackTrace();
		}
		return rc;
		
	}
}
